﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
using Model;
using WindowsForms.service;
using WindowsForms.Class;


namespace WindowsForms
{
    public partial class TableChangeProcess : DevExpress.XtraEditors.XtraForm
    {
        Service1 iQuery;
        List<Regions> lsRegion;
        List<Tables> lsTable;

        public TableChangeProcess(bool? isModifyer = null)
        {
            iQuery = new Service1();
            InitializeComponent();
            GetRegions();
            GetTable();
            if (isModifyer.HasValue)
            {
                GenerateModifyerControl(isModifyer.Value);
            }
        }

        private void GetRegions()
        {
            ConvertToList convert = new ConvertToList();
            lsRegion = convert.ConvertTolistRegions(iQuery.SelectRegionsAll().Tables[0]);
            cbRegion.Properties.DataSource = lsRegion;
        }

        private void GetTable()
        {
            ConvertToList convert = new ConvertToList();
            lsTable = convert.ConvertTolistTables(iQuery.SelectTablesAll().Tables[0]);
            cbTable.Properties.DataSource = lsTable;
        }

        private void GenerateModifyerControl(bool isModifyer)
        {
            if (isModifyer)
            {
                this.layoutControlGroupTable.Text = "Chỉnh sửa thông tin bàn";
                this.layoutControlGroupTable.CustomizationFormText = "Chỉnh sửa thông tin bàn";
                this.layoutControlGroupTable.CaptionImage = global::WindowsForms.Properties.Resources.Edit;
            }
        }
        #region get, set
        public int Table_ID
        {
            get
            {
                return (int)cbTable.EditValue;
            }
            set
            {
                cbTable.EditValue = value;
            }
        }
     
        public int Table_RegionID
        {
            get
            {
                return (int)cbRegion.EditValue;
            }
            set
            {
                cbRegion.EditValue = value;
            }
        }
   
        #endregion

        private void TableProcess_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !dxValidationTable.Validate() && DialogResult == DialogResult.OK;
        }

        private void cbRegion_EditValueChanged(object sender, EventArgs e)
        {
            GetTable();
            lsTable = lsTable.FindAll(x => x.RegionID == Table_RegionID);
            lsTable = lsTable.ToList();
            cbTable.Properties.DataSource = lsTable;
        }

        private void TableChangeProcess_Load(object sender, EventArgs e)
        {

        }
    }
}